using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using UWBGL_XNA_Lib13;
using Microsoft.Xna.Framework;

namespace XNA_SceneNode
{
	public partial class XFormInfoControl : UserControl
	{
        UWB_SceneNode mSceneNode;
		float mTranslationMin;
		float mTranslationMax;
		float mScaleMin;
		float mScaleMax;
		float mRotationMin;
		float mRotationMax;

		public XFormInfoControl()
		{
            InitializeComponent();

            mTranslationMin = -10;
            mTranslationMax = 10;
            mScaleMin = .1f;
            mScaleMax = 10;
            mRotationMin = -180;
            mRotationMax = 180;

            mSceneNode = null;
		}

        public void setSceneNode(UWB_SceneNode node)
        {
            mSceneNode = node;
            initializeSliders();
        }

		public void setSliderRange(float tmin, float tmax, float smin, float smax, float rmin, float rmax)
		{
			mTranslationMin = tmin;
			mTranslationMax = tmax;
			mScaleMin = smin;
			mScaleMax = smax;
			mRotationMin = rmin;
			mRotationMax = rmax;
		}

		public void initializeSliders()
		{
            UWB_XFormInfo xf = mSceneNode.getXFormInfo();

			if (radioTranslate.Checked)
			{
				sliderX.ChangeRangeValues(mTranslationMin, mTranslationMax, xf.getTranslation().X);
				sliderY.ChangeRangeValues(mTranslationMin, mTranslationMax, xf.getTranslation().Y);
				sliderY.Enabled = true;
			}
			else if (radioScale.Checked)
			{
				sliderX.ChangeRangeValues(mScaleMin, mScaleMax, xf.getScale().X);
				sliderY.ChangeRangeValues(mScaleMin, mScaleMax, xf.getScale().Y);
				sliderY.Enabled = true;
			}
			else if (radioRotate.Checked)
			{
				sliderX.ChangeRangeValues(mRotationMin, mRotationMax, xf.getRotationInDegrees());
				sliderY.ChangeRangeValues(mRotationMin, mRotationMax, 0);
				sliderY.Enabled = false;
			}
			else if (radioPivot.Checked)
			{
				sliderX.ChangeRangeValues(mTranslationMin, mTranslationMax, xf.getPivot().X);
				sliderY.ChangeRangeValues(mTranslationMin, mTranslationMax, xf.getPivot().Y);
				sliderY.Enabled = true;
			}
            checkBoxShowPivot.Checked = mSceneNode.isPivotVisible();
		}

		private void radioClicked(object sender, EventArgs e)
		{
			initializeSliders();
		}

		private void sliderScroll(object sender, EventArgs e)
		{
            UWB_XFormInfo xf = mSceneNode.getXFormInfo();

			float x = sliderX.GetSliderValue();
			float y = sliderY.GetSliderValue();

			if (radioTranslate.Checked)
			{
				xf.setTranslation(new Vector3(x, y, 0));
			}
			else if (radioScale.Checked)
			{
				xf.setScale(new Vector3(x, y, 1));
			}
			else if (radioRotate.Checked)
			{
				xf.setRotationDegrees(x);
			}
			else if (radioPivot.Checked)
			{
				xf.setPivot(new Vector3(x, y, 0));
			}
            mSceneNode.setXFormInfo(xf);
		}

		private void buttonReset_Click(object sender, EventArgs e)
		{
			UWB_XFormInfo xf = new UWB_XFormInfo();
            mSceneNode.setXFormInfo(xf);
			initializeSliders();
		}

		private void checkBoxShowPivot_CheckedChanged(object sender, EventArgs e)
		{
            mSceneNode.setPivotVisible(checkBoxShowPivot.Checked);
		}
	}
}
